package com.fengke.cn.yejian11.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fengke.cn.yejian11.Model.Model;
import com.fengke.cn.yejian11.R;
import com.fengke.cn.yejian11.adapter.TeaAdapter;
import com.fengke.cn.yejian11.base.BaseFragment;
import com.fengke.cn.yejian11.impls.ActImpls;
import com.fengke.cn.yejian11.javabean.TeaList;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * A simple {@link Fragment} subclass.
 */
public class TeacherFragment extends BaseFragment {
    private List<TeaList> list;
    private Context context;
    private TeaAdapter adapter;
    private View view;
    private String uid;
    private RecyclerView recyclerView;
    public TeacherFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_teacher, container, false);
        init();
        event();
        return view;
    }
 public void init()
 {
     recyclerView=(RecyclerView)view.findViewById(R.id.L_teacher);
     context=getActivity();
     uid=getUserId();

 }
 public void event()
 {
     Retrofit retrofit= Model.getConn();
     ActImpls impls=retrofit.create(ActImpls.class);
     Call<List<TeaList>> call=impls.getTeaList(1);
     call.enqueue(new Callback<List<TeaList>>() {
         @Override
         public void onResponse(Call<List<TeaList>> call, Response<List<TeaList>> response) {
             list=response.body();
             adapter=new TeaAdapter(context,list,uid);
             LinearLayoutManager manager=new LinearLayoutManager(context);
             manager.setOrientation(LinearLayoutManager.VERTICAL);
             recyclerView.setAdapter(adapter);
             recyclerView.setItemAnimator(new DefaultItemAnimator());
             recyclerView.setLayoutManager(manager);
         }

         @Override
         public void onFailure(Call<List<TeaList>> call, Throwable t) {

         }
     });
 }
}
